<template>
  <!-- 弹出框一 -->

  <vol-box
    :lazy="true"
    v-if="model1"
    v-model="model1"
    title="库位明细"
    :width="1200"
    :height="1500"
    :padding="5"
    :onModelClose="onModelClose"
  >
      <el-alert
      type="warning"
      description="当前输入的数量为调整后的数量"
      show-icon
      :closable="false"
    />
    <vol-form ref="editForm" :load-key="false" :formRules="editFormOptions" :formFields="editFormFields"> </vol-form>

    <template #footer>
      <div>
        <!-- <el-button type="primary" plain size="small" @click="callParent">调用生成(父)页面对象</el-button> -->
        <el-button type="primary" size="small" @click="closeModel1">确认</el-button>
        <el-button type="default" size="small" @click="model1 = false">关闭</el-button>
      </div>
    </template>
  </vol-box>
</template>
<script>
import VolBox from '@/components/basic/VolBox.vue'
import VolForm from '@/components/basic/VolForm.vue'

//这里使用的vue2语法，也可以写成vue3语法
export default {
  emits: ['parentCall'],
  components: { 'vol-box': VolBox, VolForm },
  methods: {},
  data() {
    return {
      model1: false,
      model1Rows: [], //弹出框1传入的选中行
      model2: false,
      model2Row: {}, //弹出框2点击的当前行数据
      editFormOptions: [
        [
          { title: '数量', required: true, field: 'qty', type: 'number', },
          { title: '批次号', required: true, field: 'lot_no' },
        ],
        [{ title: '原因', field: 'reason', required: true, type: 'textarea', colSize: 12 }],
      ],
      editFormFields: { qty: '', lot_no: '', reason: '' },
    }
  },
  methods: {
    
    openModel1(rows) {
      //弹出框1
      this.model1Rows = rows
      this.model1 = true
      this.editFormFields.qty = rows.Qty
      this.editFormFields.lot_no = rows.LotNo


    },

    

    loadBefore(param, callBack) {
      param.WarehouseId = this.model1Rows.WarehouseId
      param.MaterialId = this.model1Rows.MaterialId

      callBack(true)
    },

    closeModel1() {
      const flag = this.$refs.editForm.validate()
      flag.then(r=> {
        console.log(r)
        if(r) {
      this.http
        .get('/api/Wms_InventorySn/InventoryModify', {
          id: this.model1Rows.InventorySnId,
          ...this.editFormFields,
        })
        .then((r) => {
          this.model1 = false
          this.callParent()
          this.editFormFields = { qty: '', lot_no: '', reason: '' }
        })
        }
      })
   

    },
    callParent() {
      this.$emit('parentCall', ($parent) => {
        //$parent就是生成页面的对象，比如可以调用页面刷新，可获取的属性与方法见【生成页面文档】,$parent.xxx直接调用
        //调用刷新
        $parent.search()
        this.$message.success('库存调整成功')
        //获取所有选中的行数据
        // $parent.getSelectRows();
      })
    },
    onModelClose() {},
  },
}
</script>
